from fastapi import FastAPI
from core import deepseek, huatuogpt_vision, realtime_audio
from fastapi.middleware.cors import CORSMiddleware  # 新增
# 创建主应用实例
app = FastAPI()

# 配置CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["http://127.0.0.1:5500","http://127.0.0.1:5501"],  # 允许的来源
    allow_credentials=True,
    allow_methods=["*"],  # 允许所有HTTP方法
    allow_headers=["*"],  # 允许所有请求头
)

# 挂载子应用到不同端点
app.mount("/api/deepseek", deepseek.app)
app.mount("/api/vision", huatuogpt_vision.app) #如果电脑跑不起来就注释这行，先测试其他部分
app.mount("/api/audio", realtime_audio.app)


if __name__ == "__main__":
    import uvicorn
    uvicorn.run(
        app,
        host="0.0.0.0",
        port=8000,
        # 生产环境应禁用reload
        # reload=os.getenv("ENV") == "development"  
    )


# 服务模块	原端点	新端点
# DeepSeek	/chat	http://localhost:8000/api/deepseek/chat
# 华佗GPT视觉	/api/chat	http://localhost:8000/api/vision/api/chat
# 实时语音识别	/ws	ws://localhost:8000/api/audio/ws